﻿var story_time;

var story;

var story_index;

function story_init() {
    story = story_make([[180, part1],]);
    story_time = 0;
    story_index = 0;
}

function story_update() {   
    while (story[story_index][0] == story_time) {   
        story[story_index][1](story[story_index][2], story[story_index][3], story[story_index][4]);
        if (++story_index >= story.length) {
            story_index = 0;
            story_time = -300;
        }
    }
    story_time++;
}

function story_make(x) {
    var result = [];
    var shift = 0;
    // I don't like js for...in.
    for (i in x) {
        shift += x[i][0];
        for (j in x[i][1]) {
            x[i][1][j][0] += shift;
            result.push(x[i][1][j]);
        }
    }
    return result;
}

var part1 = [
// left enemies
[00, enemy_0, -20, HEIGHT * 0.20, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[15, enemy_0, -20, HEIGHT * 0.23, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[30, enemy_0, -20, HEIGHT * 0.26, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[45, enemy_0, -20, HEIGHT * 0.29, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[60, enemy_0, -20, HEIGHT * 0.32, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[75, enemy_0, -20, HEIGHT * 0.35, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[90, enemy_0, -20, HEIGHT * 0.38, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[105, enemy_0, -20, HEIGHT * 0.41, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[120, enemy_0, -20, HEIGHT * 0.38, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[135, enemy_0, -20, HEIGHT * 0.41, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[150, enemy_0, -20, HEIGHT * 0.38, script(move_0(2, 0, 3, pi * 0.1, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
// right enemies
[160, enemy_0, WIDTH + 20, HEIGHT * 0.20, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[175, enemy_0, WIDTH + 20, HEIGHT * 0.23, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[190, enemy_0, WIDTH + 20, HEIGHT * 0.26, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[205, enemy_0, WIDTH + 20, HEIGHT * 0.29, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[220, enemy_0, WIDTH + 20, HEIGHT * 0.32, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[235, enemy_0, WIDTH + 20, HEIGHT * 0.35, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[250, enemy_0, WIDTH + 20, HEIGHT * 0.38, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[265, enemy_0, WIDTH + 20, HEIGHT * 0.41, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[280, enemy_0, WIDTH + 20, HEIGHT * 0.38, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[295, enemy_0, WIDTH + 20, HEIGHT * 0.41, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
[310, enemy_0, WIDTH + 20, HEIGHT * 0.38, script(move_0(2, pi, 3, pi * 0.9, 90), shoot_0(enemy_bullet_0, 35, 4, pi * 0.25))],
].sort(function(a, b) {return a[0] - b[0]});
